<template>

    <el-container class="containerA">
      <el-header>
        <div class="header-div">
            <img src="../assets/vue.svg" alt="">
            <span>vue3后台管理系统</span>
           
        </div>
     <el-button @click="leave()">退出</el-button>
      </el-header>
      <el-container>
        <el-aside :width="!isCollapse ? '200px' : '64px'">
          <!--折叠-->
          <div class="toggle-button" @click="toggleCollspace()">|||</div>
            <el-menu
        active-text-color="#ffd04b"
        background-color="#333744"
        class="el-menu-vertical-demo"
        text-color="#fff"
        :router="true"
        :default-active="$route.path"
        :collapse="isCollapse"
        :collapse-transition="false"
        :unique-opened="true"
      >
        <el-sub-menu :index="item.path + ''" v-for="(item, index) in menusData" :key="index">
          <template #title>
            <el-icon><location /></el-icon>
            <span>{{ item.title }}</span>
          </template>
            <el-menu-item :index="'/' + item1.path" v-for="(item1, index1) in item.children" :key="index1">{{ item1.title }}</el-menu-item>
        </el-sub-menu>
     

      </el-menu> 

        </el-aside>
        <el-main><router-view></router-view></el-main>
      </el-container>
    </el-container>

    </template>

<script setup>
import { Location } from '@element-plus/icons-vue'
import { onMounted, reactive, toRefs } from "vue"
import axios from "axios"
import router from "../router/router"
let ress = reactive({
    menusData: [],
    isCollapse: false
})
let { menusData, isCollapse } = toRefs(ress)
//请求菜单数据
function uploadMenu() {
    axios.get("/menus").then((res) => {
        // console.log(res)
        ress.menusData = res.data
    })
}
//是否折叠
function toggleCollspace() {
    ress.isCollapse = !ress.isCollapse
}
//点击退出
function leave() {
    window.sessionStorage.removeItem("taken")
    router.push("/login")
}
onMounted(() => {
    uploadMenu()
})
</script>

<style scoped>
.containerA {
    height: 100%
}

.el-header {
    background-color: #373d41;
    color: #fff;
    font-size: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.el-aside {
    background-color: #333744;
}

.el-main {
    background-color: #eaedf1;
}

.header-div img {
    width: 60px;
    height: 60px;
    vertical-align: middle;
    margin-right: 10px;
}

.toggle-button {
    background-color: #4a5064;
    color: #fff;
    font-size: 10px;
    text-align: center;
    line-height: 24px;
    letter-spacing: 0.2em;
    cursor: pointer;
}
</style>